package com.yunhe.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.ibatis.session.SqlSession;

import com.yunhe.inter.LeavingInfoInter;
import com.yunhe.util.SqlSessionFactoryUtil;

/**
 * 处理添加留言信息
 */
@WebServlet("/AddLeavingInfoServlet")
public class AddLeavingInfoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
    public AddLeavingInfoServlet() {
        super();
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取留言内容
	    String guestContent = request.getParameter("guestContent");
	    String guestContentString =new String(guestContent.getBytes("ISO-8859-1"),"UTF-8");
	    
	    //创建数据库连接
	    SqlSession sqlSession =SqlSessionFactoryUtil.openSqlSession();
	    
	    LeavingInfoInter liiMapper =sqlSession.getMapper(LeavingInfoInter.class);
		//调用添加方法将信息入库
		liiMapper.addLeavingInfo(1, guestContentString);
		sqlSession.commit();
		response.sendRedirect("/easyBuy170601/ShowLeavingInfoServlet");
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}

}
